/**
 * Copyright (c) 2011 Tomi Paananen.
 *
 * Part of Quick Gestures engine library.
 */

#ifndef GESTUREPROCESSOR_H
#define GESTUREPROCESSOR_H

// Qt includes
#include <QLine>
#include <QList>
#include <QtGlobal>

// qgengine includes
#include "qgcommon.h"


/*!
  \class LineData
  \brief A class for storing information about a line between two points.
*/
class LineData
{
public: // Data types
    enum Direction {
        Undefined = 0,
        Up,
        Right,
        Down,
        Left
    };

public:
    LineData()
    : mSlope(0),
      mB(0),
      mIsVerticalLine(false),
      mX(0),
      mDirection(Undefined)
    {}

    ~LineData() {}

public: // Data
    qreal mSlope;
    qreal mB; // y-intercept

    // The following variables are reserved for the case in where the line has
    // no slope i.e. the equation is of form x = c.
    bool mIsVerticalLine;
    int mX;

    // The following variables are for preserving the information which is used
    // to calculate the equation. Furthermore, they allow an easy way to track
    // the direction.
    QPoint mFrom;
    QPoint mTo;
    Direction mDirection;

    qreal mLength;
};


class GestureProcessor
{
public:
    explicit GestureProcessor();
    virtual ~GestureProcessor();

public:
    QPoint topLeft(const PointList &points) const;
    QPoint center(const PointList &points) const;
    void moveTopLeft(PointList &points,
                     const QPoint &newTopLeft = QPoint(0, 0)) const;
    void moveCenter(PointList &points, const QPoint &newCenter) const;
    virtual void scale(PointList &points, quint32 scaleFactor) const;
    PointList distributePointsEvenly(const PointList &points,
                                     int wantedPointCount) const;
    virtual void mirror(PointList &points, bool operateOnXAxis) const;
    void swapXY(PointList &points) const;
    QList<QLine> pointsToLines(const PointList &points) const;
    void normalizeLine(QLine &line) const;
    qreal compareLines(const QLine &line1, const QLine &line2) const;

protected:
    qreal totalLength(const PointList &points) const;
    LineData lineData(const QPoint &point1, const QPoint &point2) const;
    int breakPointCount(const PointList &points) const;
};


#endif // GESTUREPROCESSOR_H

// End of file.
